﻿
function CompanyController($scope, service, $routeParams, $location, $http, $validator) {
    var popupOptions = {
        appendTo: $("#popup-wrapper"),
        closeClass: 'b-close',
        speed: 300
    };

    //get data of Store list api/storelist/1
    $http.get(service.locationUrl + "/company/" + service.infoUser.Id, {})
        .success(function (data) {
            $scope.company = data;
        })
        .error(function (err) {

            console.log("error", err);
        });

    $scope.save = function ()
    {
        $validator.validate($scope, "company")
           .success(function () {
               // popup detele
               $scope.title = "Do you want save that infomation ?";
               $('.popup-delete-save').bPopup(popupOptions);
               // End

               $scope.action = function () {
                   var companyObj = {
                       UserAccessId: $scope.company.UserAccessId,
                       Name: $scope.company.Name,
                       SiteName: $scope.company.SiteName,
                       IsOrganization: $scope.company.IsOrganization,
                       Phone: $scope.company.Phone,
                       Fax: $scope.company.Fax,
                       PostCode: $scope.company.PostCode,
                       City: $scope.company.City,
                       District: $scope.company.District,
                       Address: $scope.company.Address,
                       BuildingName: $scope.company.BuildingName
                   }
                   $http.put(
                           service.locationUrl + "/company/" + $scope.company.Id,
                           companyObj)
                       .success(function () {
                           $('.popup-delete-save').bPopup().close();
                       })
                       .error(function () { });
               }
           }).error(function () {
               console.log("err");
           });
    }  
}